local shacheng = fk.CreateSkill {
  name = "shacheng",
}
local func={
  anim_type = "support",
  derived_piles = "shacheng",
  expand_pile = "shacheng",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return event == fk.GameStart or (data.card.trueName == "slash" and #player:getPile(self.name) > 0 and data.tos and
        table.find(data.tos, function(id) return not player.room:getPlayerById(id).dead end))
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.GameStart then
      return true
    else
      local room = player.room
      room:setPlayerMark(player, "shacheng-tmp", table.filter(data.tos,
        function(id) return not room:getPlayerById(id).dead end))
      local success, dat = room:askForUseActiveSkill(player, "shacheng_active", "#shacheng-invoke", true)
      room:setPlayerMark(player, "shacheng-tmp", 0)
      if success then
        event:setCostData(self,dat)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      player:addToPile(self.name, room:getNCards(2), true, self.name)
    else
      room:moveCardTo(event:getCostData(self).cards, Card.DiscardPile, player, fk.ReasonJustMove, self.name, self.name, true, player)
      local to = room:getPlayerById(event:getCostData(self).targets[1])
      local n = 0
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.from == to then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                n = n + 1
              end
            end
          end
        end
      end, Player.HistoryTurn)
      if n == 0 or to.dead then return end
      to:drawCards(n, self.name)
    end
  end,
}
shacheng:addEffect(fk.CardUseFinished, func)
shacheng:addEffect(fk.GameStart, func)

return shacheng